package com.mrper.ext.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.GridView;
import android.widget.ListAdapter;

import com.miguo.framework.view.pulltorefresh.PullToRefreshAdapterViewBase;

/**
 * Created by Administrator on 2016/8/22.
 * 不带头部和底部的Pull2refresh-GridView
 */
public class PullToRefreshGridView extends PullToRefreshAdapterViewBase<GridView> {

    public PullToRefreshGridView(Context context) {
        super(context);
    }

    public PullToRefreshGridView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public PullToRefreshGridView(Context context, Mode mode) {
        super(context, mode);
    }

    @Override
    public Orientation getPullToRefreshScrollDirection() {
        return Orientation.VERTICAL;
    }

    @Override
    protected GridView createRefreshableView(Context context, AttributeSet attrs) {
        return new GridView(context, attrs);
    }

    public Object getItemAtPosition(int position){
        ListAdapter adapter = getRefreshableView().getAdapter();
        if(adapter == null) return null;
        return adapter.getItem(position);
    }

    public void setNumColumns(int count){
        getRefreshableView().setNumColumns(count);
    }

    public void setSelection(int position) {
        getRefreshableView().smoothScrollToPosition(position);
    }

}
